-- subsecuencia memorizado no generico

evalDP :: Eq a => (([a],[a]) -> Bool) -> (([a],[a]) -> Bool) -> (([a],[a]) -> [([a],[a])]) -> ([Bool] -> Bool) -> ([a],[a]) -> Bool
evalDP isBase base split join x = solution x (evalDPStore isBase base split join x [])

evalDPStore :: Eq a => (([a],[a]) -> Bool) -> (([a],[a]) -> Bool) -> (([a],[a]) -> [([a],[a])]) -> ([Bool] -> Bool) -> ([a],[a]) -> [(([a],[a]),Bool)] -> [(([a],[a]),Bool)]
evalDPStore isBase base split join (p,t) rs | pertenece (p,t) rs = rs
										    | isBase (p,t) = ((p,t), base(p,t)) : rs
											| otherwise = ((p,t),join ox): rs2
													where 
													 rs1 = evalDPStore isBase base split join (p,(tail t))  rs
													 s1 = solution (p,(tail t)) rs1
													 rs2 = evalDPStore isBase base split join (p, (init t))  rs1
													 s2 = solution (p,(init t)) rs2
													 ox = [s1,s2]
			

solution :: Eq a => ([a],[a]) -> [(([a],[a]),Bool)] -> Bool
solution x (y : ys)  | ( x == fst y) = snd y
			         | otherwise = solution x  ys

					 
pertenece :: Eq a => ([a],[a]) -> [(([a],[a]),b)] -> Bool
pertenece x [] = False
pertenece	x (y:ys) | (x == fst y) = True
					 | otherwise = pertenece x ys
 
secMemo (xs,ys) = evalDP (\x -> (length(fst x )) == (length(snd x))) (\x -> (fst x == snd x)) (\x -> [(fst x , (tail (snd x))),(fst x , (init (snd x)))]) (\x -> ((head x) || (last x))) (xs,ys)
